﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddPicCommandHander : IRequestHandler<AddPicCommand, ApiResult<object>>
    {
        public IRepistory<Picture> PictureRepistory;
        public IMapper Mapper;

        public AddPicCommandHander(IRepistory<Picture> pictureRepistory, IMapper mapper)
        {
            PictureRepistory = pictureRepistory;
            Mapper = mapper;
        }
        public Task<ApiResult<object>> Handle(AddPicCommand request, CancellationToken cancellationToken)
        {
           ApiResult<object> result = new ApiResult<object>();
           var presult=Mapper.Map<Picture>(request);
           PictureRepistory.Add(presult);
            result.Data = presult;
            result.code = Renum.添加成功;
            result.Message=Renum.添加成功.ToString();
            return Task.FromResult(result);
        }
    }
}
